import {handleSql} from '../../database/mysql/index.js'

class listOfItemsModel {
    constructor() {
        this.tableName = 'list_of_items';
    }

    // 根据事项分支id查询所有子元素
    async getListOfItemsByThingModelBranchId(thingModelBranchId) {
        const sql = `SELECT * FROM ${this.tableName} 
                     WHERE thingModelBranchId = ?`
        let result = await handleSql(sql,[thingModelBranchId])
        return result
    }


    // 新增事项清单分支下的子元素  --单条新增
    async addListOfItems(listOfItemData) {
        const {thingModelBranchId,listName,status,content} = listOfItemData
        const sql = `INSERT INTO ${this.tableName}(thingModelBranchId,itemName,status,content)  
                     VALUES (?,?,?,?)`
        let result = await handleSql(sql,[thingModelBranchId,listName,status,content])
        if(result.affectedRows == 1){
            return true
        }else{
            return false
        }
    }
}   

export default new listOfItemsModel();